package com.sca.bussiness.service.impl;

import com.sca.bussiness.feign.OrderFeignClient;
import com.sca.bussiness.feign.PointFeignClient;
import com.sca.bussiness.service.SeataService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;

/**
 * @author liuxianfei
 * @since 2020/11/13 17:00
 */
@Service
public class SeataServiceImpl implements SeataService {

    private final PointFeignClient pointFeignClient;
    private final OrderFeignClient orderFeignClient;

    public SeataServiceImpl(PointFeignClient pointFeignClient, OrderFeignClient orderFeignClient) {
        this.pointFeignClient = pointFeignClient;
        this.orderFeignClient = orderFeignClient;
    }

    @Override
    @GlobalTransactional(name = "test", timeoutMills = 20000, rollbackFor = Exception.class)
    public Boolean testSeataMethod(Integer userId, Long goodId) throws Exception {
        pointFeignClient.add(userId, 1);
        System.out.println("增加积分完成！");
        orderFeignClient.addOrder(userId, goodId, 1);
        System.out.println("创建订单成功！");
//        if(1>0){
//            throw new Exception("eee");
//        }
        return true;
    }

}
